package com.wlf.controller;

import com.wlf.constant.Constants;
import com.wlf.entity.Account;
import com.wlf.entity.ApiResponse;
import com.wlf.service.ITransferService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lingfeng.wei
 * @date 2021/10/28 11:39
 */
@RestController
public class AccountController {

    private static Logger logger = LoggerFactory.getLogger(AccountController.class);


    @Autowired
    private ITransferService transferService;

    /**
     * 转账
     * @return
     */
    @RequestMapping("/transfer")
    public ApiResponse<String> transfer(Account account){
        try {
            //TODO
            //设置 id=1 李永健 将李永健的钱转给娄伟 id=2,
            account.setId(1L);
            int status = transferService.transfer(account);
            if(status >0){
                return ApiResponse.success(Constants.RESPONSE_OK,Constants.RESPONSE_MESSAGE,"转账成功,交易金额:"+account.getTotalMoney());
            }
            return ApiResponse.success(Constants.RESPONSE_OK,Constants.RESPONSE_MESSAGE,"转账失败");

        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return ApiResponse.success(Constants.RESPONSE_ERROR,e.getMessage(),e.getMessage());
        }
    }

}
